//
//  TeacherVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/2.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "TeacherVC.h"
#import "BanJiController.h"


@interface TeacherVC ()<TeacherLeftDelegate,TCVCDelegate,BanJiControllerDelegate,JiaoXueZuoYeDelegate,JiaoXueCeShiDelegate>
@property (nonatomic, strong) NSMutableArray *dataArray;
//所有的小窗的导航
@property (nonatomic, strong) NSMutableArray *allMiniNavArray;
@property (nonatomic, strong) NSMutableArray *allViewArray;
@property (nonatomic, assign) int minuType;
@property (nonatomic, strong) BanJiController *banJiController;
@property (nonatomic, strong) JiaoCueZuoYeCollectionView *vc;
@end

@implementation TeacherVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAINBACKCOLOR;
    UIView *lineView = [UIView new];
    lineView.frame = CGRectMake(0, 20, APP_WIDTH, 1);
    lineView.backgroundColor = LINCOLOR;
    [self.view addSubview:lineView];
    // Do any additional setup after loading the view.
}
- (void)initArray{
    _allMiniNavArray = [NSMutableArray new];
    _allViewArray = [NSMutableArray new];
}
//290-75
- (TeacherLeftView *)leftMenuView{
    //@[@" 课程",@" 作业",@" 班级"]   去掉了作业   @[@"t_class.png",@"t_work.png",@"t_course.png"]
    if (!_leftMenuView) {
        TeacherLeftView *view = [[TeacherLeftView alloc]initWithFrame:CGRectMake(0, 20, 215*fw, APP_HEIGHT-20) andButtonView:@[@" 课程",@" 班级"] andImageArray:@[@"t_class.png",@"t_course.png"]];//@"t_test.png",
        view.delegate = self;
        _leftMenuView = view;
    }
    return _leftMenuView;
}

- (UIView *)baseView{
    if (!_baseView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        _baseView = view;
    }
    return _baseView;
}
#pragma mark - 添加子视图
- (void)initSubView{
    [self initArray];
    for (int i = 0; i<4; i++) {
        UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
        if (i == 3) {
            _banJiController = [[BanJiController alloc]initWithCollectionViewLayout:flow];
            _banJiController.view.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
            _banJiController.mDelegate = self;
            [_allViewArray addObject:_banJiController];
        }else if (i == 0){
            _classVC = [[TCollectionViewControllelr alloc]initWithCollectionViewLayout:flow];
            _classVC.mDelegate = self;
            [_allViewArray addObject:_classVC];
        }else if (i == 1){
            // 去掉了作业
//            _zuoYeVC = [[JiaoCueZuoYeCollectionView alloc]initWithCollectionViewLayout:flow];
//            _zuoYeVC.mDelegate = self;
//            _zuoYeVC.view.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
//            [_allViewArray addObject:_zuoYeVC];
            _banJiController = [[BanJiController alloc]initWithCollectionViewLayout:flow];
            _banJiController.view.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
            _banJiController.mDelegate = self;
            [_allViewArray addObject:_banJiController];
            
        }else if (i == 2){
//            _textVC = [[JiaoXueCeShiCollectionView alloc]initWithCollectionViewLayout:flow];
//            _textVC.mDelegate = self;
//            [_allViewArray addObject:_textVC];

        }
        [self.view addSubview:self.leftMenuView];
        [self.view addSubview:self.baseView];
        [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.leftMenuView.mas_right);
            make.top.equalTo(@20);
            make.right.equalTo(@0);
            make.bottom.equalTo(@0);
        }];
    }
    [self mineClick:0];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(goZuoYeTabbar:) name:@"TABBAR_GoZuoYe" object:nil];
}
//前往作业的方法
- (void)goZuoYeTabbar:(NSNotification *)info{
    NSString *classId = [info.userInfo objectForKey:@"classId"];
    NSString *lessonId = [info.userInfo objectForKey:@"lessonId"];
    _vc = _allViewArray[1];
    if (self.currentVC == _allViewArray[1]) {
        return;
    }else{
        [self addChildViewController:_vc];
        _vc.view.hidden = NO;
        [self.baseView addSubview:_vc.view];
        [_vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.baseView.mas_left);
            make.right.equalTo(self.baseView.mas_right);
            make.top.equalTo(@0);
            make.bottom.equalTo(self.baseView.mas_bottom);
        }];
        //替换view
        [_vc didMoveToParentViewController:self];
        [self.currentVC willMoveToParentViewController:nil];
        [self.currentVC removeFromParentViewController];
        [self.currentVC.view removeFromSuperview];
        self.currentVC.view.hidden = YES;
    }
    
    _minuType = 1;
    [self.leftMenuView selectedButton:1];
    
//    _vc.classID = classId;
//    _vc.lessionID = lessonId;
//    [_vc reloadView];
    
}
- (void)initOption{
    _dataArray = [[NSMutableArray alloc]init];
    //数组添加跟视图
    
}
- (void)layout{

}
//教学-测试-cell点击
- (void)jiaoXueCeShiDelegateCollectionViewCellClick:(NSIndexPath *)index{
    NSLog(@"cell点击 %ld",(long)index.row);
}
//教学-作业-cell点击
- (void)jiaoXueZuoYeDelegateCollectionViewCellClick:(NSIndexPath *)index{
    NSLog(@"cell点击 %ld",(long)index.row);
}
#pragma mark - 左侧按钮点击
- (void)mineClick:(int)index{
    UICollectionViewController *vc = _allViewArray[index];
    if (self.currentVC == _allViewArray[index]) {
        return;
    }else{
        [self addChildViewController:vc];
        vc.view.hidden = NO;
        [self.baseView addSubview:vc.view];
        [vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.baseView.mas_left);
            make.right.equalTo(self.baseView.mas_right);
            make.top.equalTo(@0);
            make.bottom.equalTo(self.baseView.mas_bottom);
        }];
        //替换view
        [vc didMoveToParentViewController:self];
        [self.currentVC willMoveToParentViewController:nil];
        [self.currentVC removeFromParentViewController];
        [self.currentVC.view removeFromSuperview];
        self.currentVC.view.hidden = YES;
    }
//    [_leftMenuView selectedButton:1];
    _minuType = index;
}
#pragma mark - 前往教学作业模块
- (void)goViewOfZuoYeModeul:(TheNewWorkListModel *)model{
    
    
    
//    UICollectionViewController *vc = _allViewArray[1];
//    if (self.currentVC == _allViewArray[1]) {
//        return;
//    }else{
//        [self addChildViewController:vc];
//        vc.view.hidden = NO;
//        [self.baseView addSubview:vc.view];
//        [vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.baseView.mas_left);
//            make.right.equalTo(self.baseView.mas_right);
//            make.top.equalTo(@0);
//            make.bottom.equalTo(self.baseView.mas_bottom);
//        }];
//        //替换view
//        [vc didMoveToParentViewController:self];
//        [self.currentVC willMoveToParentViewController:nil];
//        [self.currentVC removeFromParentViewController];
//        [self.currentVC.view removeFromSuperview];
//        self.currentVC.view.hidden = YES;
//    }
//    [_leftMenuView selectedButton:1];
//    JiaoCueZuoYeCollectionView *VC = (JiaoCueZuoYeCollectionView *)vc;
//    [VC goWorkDetailView:model];
//    _minuType = 4;
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"ChangeCellSpaNotice" object:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
